package com.k12.user.controller;

import com.k12.user.model.entity.SysPost;
import com.k12.user.service.SysPostService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * 岗位信息表(SysPost)表控制层
 *
 * @author makejava
 * @since 2025-07-28 20:53:09
 */
@RestController
@RequestMapping("sysPost")
public class SysPostController {
    /**
     * 服务对象
     */
    @Resource
    private SysPostService sysPostService;

    /**
     * 分页查询
     *
     * @param sysPost 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("getAllPost")
    public List<SysPost> queryByPage(SysPost sysPost) {
        return this.sysPostService.queryByPage(sysPost);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getOnePost/{id}")
    public SysPost queryById(@PathVariable("id") Long id) {
        return this.sysPostService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param sysPost 实体
     * @return 新增结果
     */
    @PostMapping("insertPost")
    public SysPost add(SysPost sysPost) {
        return this.sysPostService.insert(sysPost);
    }

    /**
     * 编辑数据
     *
     * @param sysPost 实体
     * @return 编辑结果
     */
    @PostMapping("updatePost")
    public SysPost edit(SysPost sysPost) {
        return this.sysPostService.update(sysPost);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("deletePost")
    public Boolean deleteById(Long id) {
        return this.sysPostService.deleteById(id);
    }


    @GetMapping("getPostByTenantId")
    public List<SysPost> getPostByTenantId(String tenantId) {
        SysPost sysPost = new SysPost();
        sysPost.setTenantId(Long.valueOf(tenantId));
        return this.sysPostService.queryByPage(sysPost);
    }

    @GetMapping("checkPostNameUnique")
    public SysPost checkPostNameUnique(@RequestParam("postName")String postName,@RequestParam("tenantId") Long tenantId) {
        SysPost sysPost = new SysPost();
        sysPost.setTenantId(tenantId);
        sysPost.setPostName(postName);
        return this.sysPostService.queryByPage(sysPost).get(0);
    }

    @GetMapping("checkPostCodeUnique")
    public SysPost checkPostCodeUnique(@RequestParam("postCode")String postCode,@RequestParam("tenantId") Long tenantId) {
        SysPost sysPost = new SysPost();
        sysPost.setTenantId(tenantId);
        sysPost.setPostCode(postCode);
        return this.sysPostService.queryByPage(sysPost).get(0);
    }

    @GetMapping("selectPostById")
    public SysPost selectPostById(@RequestParam("postId")Long postId,@RequestParam("tenantId") Long tenantId) {
        SysPost sysPost = new SysPost();
        sysPost.setPostId(postId);
        sysPost.setTenantId(tenantId);
        return this.sysPostService.queryByPage(sysPost).get(0);
    }


    @GetMapping("deletePostByIds")
    public int deletePostByIds(@RequestParam("postIds")Long[] postIds,@RequestParam("tenantId") String tenantId) {
        return this.sysPostService.deletePostByIds(postIds, tenantId);
    }


}

